// Client_Double.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <string>
#include <iostream>

#include <Network/TcpClient.h>
#include <Game/ClientPacketProducer.h>
#include <Game/ClientPacketHandler.h>

class GameClient : public ClientPacketHandler
{
public:
	GameClient()
		: mIoLoop(), mClient(mIoLoop, this), mPacketProducer(mClient)
	{
		mIoLoop.Start();
		mClient.Start(std::string("127.0.0.1"), std::string("9000"));
		mPacketProducer.Login(123456789);
	}

	~GameClient()
	{
		mIoLoop.Stop();
		mClient.Stop();
	}

protected: // ClientPacketHandler
	virtual void OnStarted()
	{
		std::cout << "[GameClient::OnStarted] " << std::endl;
	}
	virtual void OnStopped()
	{
		std::cout << "[GameClient::OnStopped] " << std::endl;
	}
	virtual void OnLogin(bool result)
	{
		std::cout << "[GameClient::OnLogin] " << std::endl;
	}

private:
	TcpIoLoop mIoLoop;
	TcpClient mClient;
	ClientPacketProducer mPacketProducer;
};

void processPrompt()
{
	GameClient* client = NULL;
	std::string prompt;
	do
	{
		std::cout << "$ ";
		std::getline(std::cin, prompt);

		if( "" == prompt )
		{
			fflush(stdout);
			continue;
		}
		else if( "c" == prompt )
		{
			client = new GameClient();
		}
		else if( "d" == prompt )
		{
			delete client;
			client = NULL;
		}
	}
	while( "quit" != prompt );
}

int _tmain(int argc, _TCHAR* argv[])
{
	processPrompt();

	return 0;
}

